package com.renting.modules.message.web;

import com.renting.common.config.HttpStatusConstant;
import com.renting.common.entity.Result;
import com.renting.common.entity.ResultList;
import com.renting.modules.message.entity.SimpleMessage;
import com.renting.modules.message.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class MessageController {
    @Autowired
    MessageService messageService;

    @RequestMapping(value = "v1/sys/messages/send/simpleMessage", method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin("*")
    public Result pushSimpleMessageToAll(@RequestBody SimpleMessage message) {
        try {
            Result result = new Result();
            messageService.sendSimpleMessageToAll(message);
            result.setMsg(HttpStatusConstant.SUCCESS, "");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping(value = "v1/sys/messages", method = RequestMethod.GET)
    @ResponseBody
    @CrossOrigin("*")
    public ResultList<SimpleMessage> messages(SimpleMessage message) {
        ResultList list = new ResultList();
        list.setData(messageService.findAll(message));
        return list;
    }

}
